package com.xbongbong.pro.statistic.enums;

import com.alibaba.fastjson.JSONArray;
import lombok.Getter;
import org.springframework.util.CollectionUtils;

import java.util.Objects;

/**
 * 高级计算一级枚举
 * @author xinpeng.jiang
 * @version V1.0
 * @date 2021/6/4 10:10
 * @since V1.0
 */
@Getter
public enum AdvancedComputingFirstEnum {
    /**
     * 无
     */
    NONE(0, "enum.advancedComputingFirst.name.none", "none"),
    /**
     * 同环比
     */
    YEAR_CHAIN(1, "enum.advancedComputingFirst.name.yearChain", "yearChain"),
    ;

    private final Integer code;

    private final String name;

    private final String alias;

    AdvancedComputingFirstEnum(Integer code, String name, String alias) {
        this.code = code;
        this.name = name;
        this.alias = alias;
    }

    /**
     * 判断高级计算是否没有开启同环比
     *  注：采用取反判断，用于兼容null和["none"]都是未开启的情况
     * @param advancedComputing 高级计算
     * @return boolean true未开启
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static boolean noneYearChain(JSONArray advancedComputing){
        return CollectionUtils.isEmpty(advancedComputing) || !Objects.equals(advancedComputing.getString(0), AdvancedComputingFirstEnum.YEAR_CHAIN.getAlias());
    }
}
